package com.zhrj.exam.configuration;

import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;

@Configuration
public class MessageSourceConfig {

    @Bean
    public MessageSource messageSource() {
        ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
        messageSource.setBasename("classpath:i18n/messages"); // 指向 messages.properties
        messageSource.setDefaultEncoding("UTF-8");       // 支持中文
        messageSource.setUseCodeAsDefaultMessage(true);  // 避免找不到 key 时抛出异常
        return messageSource;
    }
}